import React, { Component } from "react";
import { connect } from "react-redux";
import QRCode from "qrcode.react";
import MainLayout from "../../../../component/mainLayout/mainLayout";
import { getAppPlatformsDatas } from "../../../../Redux/Action/nativeDatas/nativeDatas";
import { setUserType } from "../../../../Redux/Action/credit/AuthenticationA";
import "./index.scss";
// import yhTools from "../../../../tools/yh";
// import xhfConfig from "../../../../config/XHFConfig";
// import { Toast, Modal } from "antd-mobile";

class inviteQrCode extends Component {
	constructor(props) {
		super(props);
		this.state = {
			qrContent: "" //二维码内容
		};
	}

	componentDidMount() {
		const url = sessionStorage.getItem("inviteUrl") || "";
		if (url) {
			this.setState({
				qrContent: url
			});
		}
	}

	goBack() {
		sessionStorage.removeItem("inviteUrl");
		this.props.history.push("/inviteHome");
	}

	render() {
		const _pageParams = {
			header: {
				title: "",
				goBackAction: () => {
					this.goBack();
				},
				rightButt: "活动规则",
				rightButtCallBack: () => {
					this.props.history.push("inviteRule");
				}
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles
		};

		return (
			<MainLayout pageParams={_pageParams}>
				<div className="invite_qrcode">
					<div className="qrcode_bg">
						<div className="qrcode">
							<QRCode value={this.state.qrContent} className="code"></QRCode>
						</div>
					</div>
					<div
						className="btn_close"
						onClick={() => {
							this.goBack();
						}}
					>
						关闭
					</div>
				</div>
			</MainLayout>
		);
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps(dispatch) {
	return {
		_getAppPlatformsDatas: options => {
			// 同步数据
			dispatch(getAppPlatformsDatas(options));
		},
		_setUserType: options => {
			dispatch(setUserType(options));
		}
	};
}

export default connect(mapStateToProps, mapDispatchToProps)(inviteQrCode);
